package com.woniuxy.controller;

import com.woniuxy.model.entity.Customers;
import com.woniuxy.service.CustomersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/customers")
public class CustomerController {
    
    @Autowired
    private CustomersService customersService;

    @GetMapping("/info")
    public ResponseEntity<Customers> getCurrentCustomerInfo(@RequestHeader("Authorization") String token) {
        try {
            // 通过 token 获取当前登录用户信息
            Customers customer = customersService.isLogged(token);

            if (customer != null) {
                return ResponseEntity.ok(customer);
            } else {
                return ResponseEntity.notFound().build();
            }
        } catch (Exception e) {
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
        }
    }
}